class Wskdeploy < Formula
  desc "Apache OpenWhisk project deployment utility"
  homepage "https://openwhisk.apache.org/"
  url "https://github.com/apache/openwhisk-wskdeploy/archive/1.1.0.tar.gz"
  sha256 "caf1f147c363a7324ce0c5d9851794c5671f56712888004c0db644de8f2a2169"
  license "Apache-2.0"

  bottle do
    sha256 cellar: :any_skip_relocation, arm64_big_sur: "681984dc7d97f45477252e42ca8dd8a3cd8758f274bbf8d2cc92613dda4f023d"
    sha256 cellar: :any_skip_relocation, big_sur:       "79a5cf98448c501d441edcd2bacb5c84cac9a3a7702ec8f9d3aa78ae05dc586a"
    sha256 cellar: :any_skip_relocation, catalina:      "ea50064881e77fc755335751edfbd5a37d8c858d77dd6d9fc336be3af3fdbc18"
    sha256 cellar: :any_skip_relocation, mojave:        "90b92ae3d73e3bb529b9b777e43842accab85e0dadf5b289d6c3eefeb15377a0"
    sha256 cellar: :any_skip_relocation, high_sierra:   "4cdc4d3314a16347a1f22367d5a21590ddda64e67fdeb015f050f9d14f12fdf5"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "012cce1dad4da628a657618e212106443dacfee87b44ad79d5cef4f558a43cd8"
  end

  depends_on "go" => :build

  def install
    system "go", "build", *std_go_args, "-ldflags", "-X main.Version=#{version}"
  end

  test do
    assert_match version.to_s, shell_output("#{bin}/wskdeploy version")

    (testpath/"manifest.yaml").write <<~EOS
      packages:
        hello_world_package:
          version: 1.0
          license: Apache-2.0
    EOS

    system bin/"wskdeploy", "-v",
                            "--apihost", "openwhisk.ng.bluemix.net",
                            "--preview",
                            "-m", testpath/"manifest.yaml",
                            "-u", "abcd"
  end
end
